package com.shen.JUC.sup;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

public class CyclicBarrierDemo {

    public static void main(String[] args) {
        CyclicBarrier barrier = new CyclicBarrier(7,()->{
            System.out.println("召唤boss");
        });
        for (int i = 0; i < 7; i++) {
            final int temp =i;
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+"收集了第"+temp);
                try {
                    barrier.await(); //等待计数器完成
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (BrokenBarrierException e) {
                    e.printStackTrace();
                }
            }).start();
        }
    }

}
